package com.meichis.yndms.ui.activity;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.meichis.yndms.R;
import com.meichis.yndms.adapter.StaffAdapter;
import com.meichis.yndms.databinding.ActivityStaffListBinding;
import com.meichis.yndms.ui.common.BaseActivity;
import com.meichis.yndms.vm.StaffListVM;

public class StaffListActivity extends BaseActivity {

    private ActivityStaffListBinding binding;
    private StaffListVM vm;
    private StaffAdapter adapter;

    @Override
    protected void setDataBindingContentView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_staff_list);
        vm = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(StaffListVM.class);

        binding.setLifecycleOwner(this);
    }

    @Override
    protected void init() {
        binding.navigation.txtTitle.setText("人员选择");
        binding.navigation.navBack.setOnClickListener(v -> onBackPressed());
        addObserver();

        vm.GetStaffList();
//        Intent intent = new Intent(this, VstTravelActivity.class);
//        intent.putExtra(MCode.STAFF, "1-6099DA");
//        startActivity(intent);
    }

    private void addObserver() {
        vm.getShowDialog().observe(this, aBoolean -> showLoading(aBoolean));
        vm.getStaffList().observe(this, staffs -> {
            adapter = new StaffAdapter(this, R.layout.item_staff, staffs);
            binding.rc.setLayoutManager(new LinearLayoutManager(this));
            binding.rc.setAdapter(adapter);
        });
    }
}
